package cn.iocoder.mall.shop.service.mapper;

import cn.iocoder.mall.shop.service.entities.Shop;
import cn.iocoder.mall.shop.service.entities.ShopClerkRelationShip;
import cn.iocoder.mall.shop.service.entities.ShopDTO;
import cn.iocoder.mall.shop.service.entities.ShopSellerRe;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description: 商铺
 * @Author: jeecg-boot
 * @Date:   2019-10-23
 * @Version: V1.0
 */
@Mapper
public interface ShopMapper extends BaseMapper<Shop> {

    /**
     * 保存商户商铺关联关系
     * @param shopId
     * @param sellerId
     * @param creatTime
     * @return
     */
    int saveRelationshipTable(@Param("shopId") String shopId, @Param("sellerId") String sellerId, @Param("creatTime") String creatTime);

    /**
     * 逻辑删除商铺
     * @param id
     */
    void removeShopById(String id);

    /**
     * 批量逻辑删除商铺
     * @param list
     * @return
     */
    int removeShopByIds(@Param("list") List<String> list);
    @Delete("delete from shop_clerk_relationship where  clerk_id=#{clerkId}")
    void deleteAllRelationShip(String clerkId);

    List<Shop> getAllShopListOfSeller(Page page, @Param("id") String sellerId);

    @Select("select * from seller_shop_relationship where shop_id = #{id} limit 1 ")
    ShopSellerRe getShopSellerShipByShopId(@Param("id") String id);

    @Delete("delete  from  seller_shop_relationship   where shop_id  =   #{id} ")
    void deleteSellerShopRelationByShopId(@Param("id") String shopId);

    /**
     * 获取该商户下的店铺列表
     * @param sellerId
     * @return
     */
    List<ShopDTO> getListOfStores(@Param("id") String sellerId);


    List<ShopDTO> getShopLisBySellerId(@Param("id") String sellerId);


    @Insert("insert into  seller_shop_relationship  (seller_id, shop_id) values ( #{sellerId},#{shopId})")
    boolean addSellerShopRelationShip(@Param("sellerId") String id, @Param("shopId") String id1);

    /**
     * 获取店员所属店铺列表
     * @param clerkId
     * @return
     */
    List<ShopDTO> queryClerkBelongShops(@Param("clerkId") String clerkId);


    @Select("select id from  seller_shop_relationship  where seller_id = #{id} and shop_id = #{shopId} limit 1 ")
    ShopClerkRelationShip getShopSellerShipBySellerIdAndShopId(@Param("id") String userId,@Param("shopId") String shopId);
    /**
     * 通过店铺id获取店铺的信息
     * @param shopIds
     * @return
     */
    List<ShopDTO> getById(@Param("shopIds") List<String> shopIds);

    IPage<Shop> getListByCoordinate(Page page, @Param("coordinate") String co);



    boolean updateStatus(@Param("id")String shopId,@Param("status")Integer status);

    @Update("update shop set shop_status = #{status} where  id  = #{id}")
    boolean updateShopStatus(@Param("id")String shopId,@Param("status")Integer status);


    Boolean addShopIncome(@Param("id") String shopId,@Param("income") Integer income);

    List<ShopDTO> getByClerkIds(@Param("ids") List<String> clerkIds);

    List<Shop> getShopPageListOfCelrk( Page page, @Param("id")String userId);
}
